package com.hl.web;

import com.alibaba.fastjson.JSON;
import com.hl.dao.ShopDaoimpl;
import com.hl.pojo.PanghuShop;
import com.hl.util.GeneralResult;
import com.hl.util.PageResult;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/shop/querySearchShopList")
public class ShopList extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        请求参数：pageNum=1&pageSize=10&phone=&keyword=&shopStatus=&startTime=&endTime=
        String pageNum = req.getParameter("pageNum");
        String pageSize = req.getParameter("pageSize");
        String phone = req.getParameter("phone");
        String keyword = req.getParameter("keyword");
        String shopStatus = req.getParameter("shopStatus");
        String startTime = req.getParameter("startTime");
        String endTime = req.getParameter("endTime");
        List<PanghuShop> list = null;
        //调用sql，查询数据
        list = new ShopDaoimpl().search(pageNum,pageSize,phone,keyword,shopStatus,startTime,endTime);
        //返回数据
        PageResult pageResult = new PageResult(list);
        GeneralResult result = new GeneralResult(200,"查询成功",pageResult);
        //返回数据
        resp.setContentType("application/json;charset=utf-8");
        //JSON.toJSONString(result)  把任意类型数据转为json格式字符串
        resp.getWriter().append(JSON.toJSONString(result));
    }
}
